package com.mazaiting.course.exception;

/***
 * 自定义异常
 * @author danghailiang
 * @datetime 2022/3/8
 */
public class CustomException extends RuntimeException {


    //状态码
    private Integer code;

    //错误消息
    private String message;


    public CustomException(){}

    public CustomException(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public CustomException(Integer code,String message,Throwable cause){
        super(cause);
        this.code = code;
        this.message = message;
    }

    public CustomException(ExceptionEnum resultCodeEnum){
        this.code = resultCodeEnum.getStatus();
        this.message = resultCodeEnum.getMessage();
    }

    public CustomException(ExceptionEnum resultCodeEnum,Throwable cause){
        super(cause);
        this.code = resultCodeEnum.getStatus();
        this.message = resultCodeEnum.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}
